﻿using System.IO;
using System.Net;
using System.Text;
using Microsoft.SPOT;

public class SimplePutRequest
{
    public static void Main()
    {
        const string apiKey = "<insert your API key here>";
        const string feedId = "<insert your feed ID here>";

        // this is the "sample" we want to send to Pachube
        var sample = "number,42";
        // convert sample to byte array
        byte[] buffer = Encoding.UTF8.GetBytes(sample);

        // produce request
        var requestUri =
            "http://api.pachube.com/v2/feeds/" + feedId + ".csv";
        using (var request = (HttpWebRequest)WebRequest.Create(requestUri))
        {
            request.Method = "PUT";

            // headers
            request.ContentType = "text/csv";
            request.ContentLength = buffer.Length;
            request.Headers.Add("X-PachubeApiKey", apiKey);

            // content
            Stream s = request.GetRequestStream();
            s.Write(buffer, 0, buffer.Length);

            // send request and receive response
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                // consume response
                Debug.Print("Status code: " + response.StatusCode);
            }
        }
    }
}
